package cn.lagou.controller;

import cn.lagou.pojo.Resume;
import cn.lagou.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {

    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/login")
    public String login(HttpSession session, String username, String pwd) {
        if ("admin".equals(username) && "admin".equals(pwd)) {
            session.setAttribute("username", username);
            session.setAttribute("pwd", pwd);

            List<Resume> resumes = resumeService.findAll();
            session.setAttribute("resumes",resumes);
            return "redirect:/resume/findAll";

        } else if (null != username && null != pwd) {
            session.setAttribute("msg","Username or password input error, Please try again!");
        }
        return "login";
    }

    @RequestMapping("/without")
    public String loginOut(HttpSession session) {
        System.out.println("......loginOut()");
        session.invalidate();
        return "redirect:/login";
    }
}
